home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8380 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.umbc.edu!not-for-mail
  2. From: schlein@umbc.edu (Jonas J. Schlein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Towers of Hanoi
  5. Date: 3 Mar 1996 16:38:19 -0500
  6. Organization: University of Maryland Baltimore County
  7. Message-ID: <4hd3gb$4v9@umbc9.umbc.edu>
  8. References: <4h5gq7$bmo@useneta1.news.prodigy.com>
  9. NNTP-Posting-Host: umbc9.umbc.edu
  10. NNTP-Posting-User: schlein
  11.  
  12. Craig Bellet <ELFW44A@prodigy.com> wrote:
  13. |> Learning to program in C++. Assigned problem of moving four progressively 
  14. |> larger rings sitting on a peg to another peg one ring at a time. The 
  15. |> object is to move the stack of rings to another peg. A small ring may be 
  16. |> placed upon a larger ring or an empty peg but not upon a larger ring. A 
  17. |> third peg is to facilitate this by temporarily holding rings. The 
  18. |> solution involves recursion but I am unable to figure out the algorithm. 
  19. |> Any thoughts?
  20.  
  21. Assigned you say? I say do you own homework...On a side note the solution
  22. to this is very easily done recursively, but an iterative version using
  23. a user defined stack isn't much harder (maybe longer). Many books also
  24. have solutions with complete code. You just have to look. I have a solution
  25. in Pascal from "Pascal" 4th Edition by Elliott B. Koffman. The solution
  26. they gave is approx 10 lines of code. Give it some thought and try to do
  27. small test cases by hand to get the algorithm down pat.
  28. -- 
  29. "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
  30.  
  31. Jonas J. Schlein  (schlein@gl.umbc.edu)
  32.